<!DOCTYPE html>
<html>
  
  <head>
    <meta charset="UTF-8">
    <title>admin2.0</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />
    <link rel="stylesheet" href="./css/font.css">
    <link rel="stylesheet" href="./css/xadmin.css">
    <script type="text/javascript" src="js/jquery-3.3.1.min.js"></script>
    <script type="text/javascript" src="./lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="./js/xadmin.js"></script>
    <script type="text/javascript" src="js/common.js"></script>
    <script type="text/javascript" src="js/formedit.js"></script>
  </head>
  
  <body>
    <div class="x-body">
        <form id="fm" class="layui-form">
          <input type="hidden" name="id"/>
          <div class="layui-form-item">
              <label for="L_username" class="layui-form-label">
                  <span class="x-red">*</span>用户名
              </label>
              <div class="layui-input-inline">
                  <input type="text" id="L_username" name="username" required="" lay-verify="nikename"
                  autocomplete="off" class="layui-input" disabled="disabled">
              </div>
              <div class="layui-form-mid layui-word-aux">
                  <span class="x-red">*</span>无法更改
              </div>
          </div>
          
          <div class="layui-form-item">
              <label for="L_pass" class="layui-form-label">
                  <span class="x-red">*</span>密码
              </label>
              <div class="layui-input-inline">
                  <input type="password" id="L_pass" name="password" required="" lay-verify="pass"
                  autocomplete="off" class="layui-input">
              </div>
          </div>
          
          <div class="layui-form-item">
              <label for="L_email" class="layui-form-label">
                  <span class="x-red">*</span>电话
              </label>
              <div class="layui-input-inline">
                  <input type="text" id="L_telphone" name="telphone" required="" lay-verify="telphone"
                  autocomplete="off" class="layui-input">
              </div>
          </div>
          
          <div class="layui-form-item">
              <label for="L_email" class="layui-form-label">
                  <span class="x-red">*</span>年龄
              </label>
              <div class="layui-input-inline">
                  <input type="text" id="L_age" name="age" required="" lay-verify="age"
                  autocomplete="off" class="layui-input">
              </div>
          </div>
          
          <div class="layui-form-item">
              <label for="L_email" class="layui-form-label">
                  <span class="x-red">*</span>性别
              </label>
              <div class="layui-input-inline">
                   <select name="sex" lay-verify="">
					  <option value="男" selected>男</option>
					  <option value="女">女</option>
					</select>   
              </div>
          </div>
          
          <div class="layui-form-item">
              <label for="L_repass" class="layui-form-label">
              </label>
              <button  class="layui-btn" lay-filter="add" lay-submit="">保存</button>
          </div>
      </form>
    </div>
    <script type="text/javascript">
          /**请求编辑的内容*/
          var id=getQueryStringByName("id");
          $.get("/user/info/"+id,function(res){
        	  $("#fm").formEdit(res.data);
        	  $("select[name='sex']").val(res.data.sex);
          })
    </script>
    
    
    <script>
      layui.use(['form','layer'], function(){
        $ = layui.jquery;
        var form = layui.form
        ,layer = layui.layer;
      

        //监听提交
        form.on('submit(add)', function(data){
        	  var formData=JSON.stringify(data.field);
	          console.log(formData);
	          //发异步，把数据提交给后台
	          $.ajax({
	          	type:"post",
	          	url:"/user/update",
	          	data:formData,
       			contentType: "application/json;charset=utf-8",
       			dataType: "json",//预期服务器返回的数据类型
       			async:false,
       			success:function(result){
       				console.log(result);//打印服务端返回的数据
       				layer.alert("保存成功", {icon: 6},function () {
	                // 获得frame索引
	                var index = parent.layer.getFrameIndex(window.name);
	                //关闭当前frame
	                parent.layer.close(index);
	                //刷新父页面表格
	                parent.layui.table.reload('idTest',{page: {curr: 1}});//idTest是表格的id；
          		});
       			},
       			error:function(){
       				layer.alert("保存失败", {icon: 5});
       			}
	          });
	          return false;
	        });
      });
  </script>
  </body>

</html>